'use strict';

export default class extends think.controller.base {
  /**
   * some base method in here
   */
   /*获取一个socket的连接*/
   getSocket(key){
        var socketaArr = thinkCache(thinkCache.WEBSOCKET,'MYWEBSOCKETS');
        if(socketaArr[key] != undefined && !think.isEmpty(socketaArr[key])){
            var socketid = socketaArr[key];
            return this.http.io.sockets.connected[socketid];
            //return socketaArr[key];
        }
        return false;
    }
    /*设置一个sok*/
    setSocket(key,value){
        if(think.isEmpty(key) && this.getSocket(key) != false){
            return false;
        }
        var socketaArr = thinkCache(thinkCache.WEBSOCKET,'MYWEBSOCKETS');

        if(socketaArr === undefined || think.isEmpty(socketaArr)){
            socketaArr = [];
        }
        socketaArr[key] = value
        thinkCache(thinkCache.WEBSOCKET,'MYWEBSOCKETS',socketaArr);
        return true;
    }
}